<?php


class Marjory_Service_ResponseWriter_Exception extends Marjory_Exception
{
}

class Marjory_Service_ResponseWriter {
    public static $defaultWriterType = 'XML';

    final public static function factory($writerType)
    {
        $wt = trim($writerType);
        /* @todo strip all illegal characters from writer type, allow alphanumeric only */
        if (!file_exists(dirname(__FILE__).'/ResponseWriter/' . $wt . '.php')) {
            Marjory_Service::getLog()->debug("Writer type $wt not found, defaulting to XML");
            $wt = 'XML';
        }
        $class = 'Marjory_Service_ResponseWriter_' . $wt;
        $file  = dirname(__FILE__).'/ResponseWriter/' . $wt . '.php';
        Marjory_Service::getLog()->debug("ResponseWriter class '$class', file '$file'.");
        include_once $file;
        if (!class_exists($class)) {
            throw new Marjory_Service_ResponseWriter_Exception("Class '$class' not found in file '$file'.");
        }
        return new $class(true);
    }
}
